package com.shaozi.nc.data.mongodao;

import java.util.HashMap;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.mongodb.core.MongoTemplate;
import org.springframework.stereotype.Repository;

import com.shaozi.lib.throwable.SzException;
import com.shaozi.nc.bean.resp.ReqSecretaryTypeBadgeBean;
import com.shaozi.nc.bean.resp.ReqSecretaryUnreadMessageTotalBean;
import com.shaozi.nc.bean.resp.RespOperationTypeBadgeBean;
import com.shaozi.nc.bean.resp.RespOperationUnreadMessageTotalBean;
import com.shaozi.nc.data.model.OperationModel;
import com.shaozi.nc.data.model.SecretaryModel;

@Repository("operationMDao")
public class OperationMDao extends BaseSecretaryMDao<OperationModel> {

	@Autowired
	public OperationMDao(MongoTemplate shaoziTemplate) {
		super(shaoziTemplate);
	}

	@Override
	protected Class getClassSon() {
		return OperationModel.class;
	}

	@Override
	public Map getTypeBadge(ReqSecretaryTypeBadgeBean reqBean) throws SzException {
		Map<String, RespOperationTypeBadgeBean> ret = new HashMap<>();
		commonGetTypeBadge(ret, reqBean, SecretaryModel.class);
		return ret;
	}

	@Override
	public RespOperationUnreadMessageTotalBean unreadMessageTotal(ReqSecretaryUnreadMessageTotalBean reqBean)
			throws SzException {
		SecretaryModel model = findOneByParams(reqBean);
		if (model == null)
			return null;
		RespOperationUnreadMessageTotalBean respBean = new RespOperationUnreadMessageTotalBean();
		respBean.setOperation((OperationModel) model);
		int count = unreadMessageTotalCount(reqBean);
		respBean.setCount(count);
		return respBean;
	}
}
